/**
 * @fileOverview Base Cube框架基类
 * @author <a href="mailto:simonsliu@tencent.com">simonsliu</a>
 * @date 11-11-24 - 下午12:48
 */
(function() {
	/**
	 * @name Cube.Base
	 * @class
	 * @exports Base as Cube.Base
	 */
	var Base = Cube.Base = function() {};


	Base.prototype = {
		constructor: function() {
			return this;
		},
		/**
		 * 返回当前所属类名
		 * @return {String} 类名
		 */
		$className: function() {
			return 'Cube.Base';
		},
		/**
		 * 返回当前所属类
		 * @return {Cube.Base} 所属类
		 */
		$class: function() {
			return Base;
		},
		/**
		 * 返回自身类
		 * @return {Cube.Base} 自身类
		 */
		$self: function $self() {
			return Base;
		}
	}
	/** @lends Cube.Base */
	Cube.merge( Base, {
		/**
		 * 可继承的静态变量列表
		 * @return {String[]} 可扩展的静态成员名称数组
		 */
		$inheritableStatics: function $inheritableStatics() {
			return [
				'$inheritableStatics',
				'$create'
			]
		},
		/**
		 * 类名
		 * @static
		 * @return {String} 当前类的名称字符串
		 */
		$name: function $name() {
			return 'Cube.Base';
		},
		/**
		 * 创建实例
		 * @return {Cube.Base} 创建的实例
		 */
		$create: function $create() {
			var args = [], a, c;

			for ( var i = 0; i < arguments.length; i++ ) {
				args.push( 'a[' + i + ']' );
			}
			console.log( args );
			return (new Function('c', 'a', 'return new c(' + args.join(',') + ')'))(this, arguments);
			
			//return this.prototype.constructor.apply( this, arguments );
		},
		/**
		 * 实现接口
		 * @param {PlainObject} members 接口名称与实现键值对
		 */
		$implement: function $implement( members ) {
			var prototype = this.prototype,
                enumerables = Cube.enumerables,
                name, i, member;
            //<debug>
            var className = this.$name();
            //</debug>
            for (name in members) {
                if (members.hasOwnProperty(name)) {
                    member = members[name];

                    if (typeof member === 'function') {
                        member.$owner = this;
                        member.$name = name;
                        //<debug>
                        if (className) {
                            member.displayName = className + '#' + name;
                        }
                        //</debug>
                    }

                    prototype[name] = member;
                }
            }

            if (enumerables) {
                for (i = enumerables.length; i--;) {
                    name = enumerables[i];

                    if (members.hasOwnProperty(name)) {
                        member = members[name];
                        member.$owner = this;
                        member.$name = name;
                        prototype[name] = member;
                    }
                }
            }
		}
	});
})();